package com.lkl.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author lkl
 * @Description
 * @Date 2022/3/30
 */
@Configuration
public class TravelMqConfig {

    @Bean(name = "tg-pay-travel")
    public Queue payQueue(){

        Map map = new HashMap();
        map.put("x-max-length", 1000);
        //设置队列中的消息溢出后,该队列的行为:"拒绝接收"(所有消息),则最近发布的消息将被丢弃
        map.put("x-overflow", "reject-publish");

        return new Queue("tg-pay-travel",false,false,false,map);
    }

    @Bean(name = "tg-pay-exchange")
    public DirectExchange directExchange(){

        return new DirectExchange("tg-pay-exchange");
    }

    @Bean
    public Binding binding(@Qualifier("tg-pay-travel")Queue queue,@Qualifier("tg-pay-exchange")DirectExchange directExchange){

        return BindingBuilder.bind(queue).to(directExchange).with("pay-travel");
    }




}
